package vlms.perfTest;

import java.sql.Connection;
import java.sql.DriverManager;

import vlms.dao.PersonDAO;
import vlms.util.JDBCConnectionDriver;

public class CachingTest {

	private static final int numberOfCalls = 10000;
	public static void main(String a[])
	{
		int index = 0;
		long startTime = 0;
		
		System.out.println("==============Caching Performance test==============");
		try {
			new JDBCConnectionDriver("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/vlmsdb", "root", "root", 10);
			
			startTime = System.currentTimeMillis();
			index = 0;
			System.out.println("Starting the test..");
			while (index < numberOfCalls)
			{
				Connection conn1 = DriverManager.getConnection("jdbc:user_mysql:");
				PersonDAO p = new PersonDAO();
				p.findExecutingUserSelect("select * from person", new Object[0], conn1);
				index++;
				conn1.close();
			}
			
			System.out.println("Time taken per call  without caching: "+ (float)(System.currentTimeMillis() - startTime)/ numberOfCalls);

			index = 0;
			startTime = System.currentTimeMillis();
			while (index < numberOfCalls)
			{
				Connection conn2 = DriverManager.getConnection("jdbc:user_mysql:");
				new PersonDAO().findAll(conn2);			
				index++;
				conn2.close();
			}
			System.out.println("Time taken per call with caching: "+ (float)(System.currentTimeMillis() - startTime)/ numberOfCalls);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
